//
//  HUDPopupVC.swift
//  BWPanelKit
//
//  Created by zhuxuhong on 2022/3/7.
//

import UIKit
import BWToolKit
import BWPopupView

class HUDPopupVC: HUDVC {
    @IBOutlet weak var wrapperView: UIView!
    @IBOutlet weak var button: UIButton!
    
    private var popup: HUD.Popup? {
        return hud as? HUD.Popup
    }
    
    override func setupStyles() {
        super.setupStyles()
        
        wrapperView?.backgroundColor = .clear
    }

    override func setupHUDView() {
        super.setupHUDView()
        
        setupAction()
    }
    
    private func setupAction(){
        if let ac = popup?.action {
            button.isHidden = false
            button.tintColor = HUD.shared.appearance.tintColor
            button.titleLabel?.font = HUD.shared.appearance.textFont.bold
            button.setImage(ac.icon, for: .normal)
            button.setTitle(ac.title, for: .normal)
            button.bw_tapped{ [weak self] _ in
                guard let self = self else { return }
                self.dismiss(completion: self.completion)
            }
        }
        else {
            button.isHidden = true
        }
    }
    
    override func dismiss(completion: BlockVoid? = nil) {
        (parent as? BWPopupController)?.dismiss(completion: completion)
    }
    
    override func animateInitial() {
    }
    
    override func animateHUDView(isIn: Bool) {
    }
}
